//
//  Int+Ex.swift
//  FastComponent
//
//  Created by lxf on 2022/10/27.
//

import Foundation


public extension Bool{
    
    func toUInt8()->UInt8{
        return self ? 1 :0
    }
    
}
public extension Int{
    // truncating
    func toUInt8()->UInt8{
        let uint8self = UInt8.init(truncating: self as NSNumber)
        return uint8self
    }
    // truncating
    func toInt8()->Int8{
        let int8self = Int8.init(truncating: self as NSNumber)
        return int8self
    }
}
public extension Array  where Element == Int{
    func toUInt8List()->[UInt8]{
        return map { v in
            v.toUInt8()
        }
    }
}
public extension Array  where Element == UInt8{
    
    func toHexList()->[String]{
        return map { e in
            Int(e).toHex()
        }
    }
    
    mutating func safe_replece(indexs:[Int],values:[Int]){
        guard indexs.count != 0,indexs.count  == values.count else {
            return
        }
        
        indexs.forEach { i, indexV in
            if i < 0 || i >= self.count{
                XXLoger.e("fastcomponent:  out of range!!!")
                return
            }
            
            self[indexV] = values[i].toUInt8()
        }
    }
}
